home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH15 / STRASIGN.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-02-25  |  1.6 KB  |  91 lines

  1. ; StrAssign.asm
  2. ;
  3. ; Demonstration of a string assignment routine.
  4.  
  5.         include        stdlib.a
  6.         includelib    stdlib.lib
  7.  
  8. cseg        segment    para public ╘code╒
  9.         assume    cs:cseg, ds:dseg, es:dseg, ss:sseg
  10.  
  11. ; String assignment procedure
  12.  
  13. MainPgm        proc    far
  14.         mov    ax, seg dseg
  15.         mov    ds, ax
  16.         mov    es, ax
  17.  
  18.         lea    di, ToString
  19.         call    StrAssign
  20.         byte    ╥This is an example of how the ╥ 
  21.         byte    ╥StrAssign routine is used╙,0
  22.         nop
  23.         ExitPgm
  24. MainPgm        endp
  25.  
  26. StrAssign    proc    near
  27.         push    bp
  28.         mov    bp, sp
  29.         pushf
  30.         push    ds
  31.         push    si
  32.         push    di
  33.         push    cx
  34.         push    ax
  35.         push    di        ;Save again for use later.
  36.         push    es
  37.         cld
  38.  
  39. ; Get the address of the source string
  40.  
  41.         mov    ax, cs
  42.         mov    es, ax
  43.         mov    di, 2[bp]    ;Get return address.
  44.         mov    cx, 0ffffh    ;Scan for as long as it takes.
  45.         mov    al, 0        ;Scan for a zero.
  46.     repne    scasb            ;Compute the length of string.
  47.         neg    cx        ;Convert length to a positive #.
  48.         dec    cx        ;Because we started with -1, not 0.
  49.         dec    cx        ;skip zero terminating byte.
  50.  
  51. ; Now copy the strings
  52.  
  53.         pop    es        ;Get destination segment.
  54.         pop    di        ;Get destination address.
  55.         mov    al, cl        ;Store length byte.
  56.         stosb
  57.  
  58. ; Now copy the source string.
  59.  
  60.         mov    ax, cs
  61.         mov    ds, ax
  62.         mov    si, 2[bp]
  63.     rep    movsb
  64.  
  65. ; Update the return address and leave:
  66.  
  67.         inc    si        ;Skip over zero byte.
  68.         mov    2[bp], si
  69.  
  70.         pop    ax
  71.         pop    cx
  72.         pop    di
  73.         pop    si
  74.         pop    ds
  75.         popf
  76.         pop    bp
  77.         ret
  78. StrAssign    endp
  79.  
  80. cseg        ends
  81.  
  82. dseg        segment para public ╘data╒
  83. ToString    byte    255 dup (0)
  84. dseg        ends
  85.  
  86. sseg        segment para stack ╘stack╒
  87.         word    256 dup (?)
  88. sseg        ends
  89.         end    MainPgm
  90.  
  91.